<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>处方笺</title>
</head>

<body>
<style>
    * {
        margin: 0;
        padding: 0;
        font-family: "Microsoft Yahei";
    }

    .fl {
        float: left;
    }

    .fr {
        float: right;
    }

    .main {
        width: 824px;
        padding: 30px 25px 15px;
        background-color: #fff;
        margin: 0 auto;
        font-size: 25px;
        overflow: hidden;
        box-sizing: border-box;
    }

    .main h1 {
        height: 46px;
        line-height: 46px;
        font-size: 46px;
        text-align: center;
        font-weight: normal;
    }

    .flexAlign {
        display: -webkit-flex;
        display: -moz-flex;
        display: -ms-flex;
        display: flex;
        -webkit-justify-content: space-between;
        justify-content: space-between;
    }

    .flexMain {
        -webkit-flex: 1;
        -moz-flex: 1;
        -ms-flex: 1;
        flex: 1;
    }

    .nameList {
        min-height: 30px;
        padding-right: 50px;
        width: 33.3%;
        padding-top: 20px;
    }

    .nameList p {
        border-bottom: 2px solid #000;
        min-height: 28px;
        line-height: 28px;
        position: relative;
        top: 2px;
        margin-left: 5px;
    }

    .nameList:last-of-type {
        padding-right: 0;
    }

    .drugBox {
        min-height: 660px;
        border: 2px solid #000;
        margin-top: 25px;
        padding: 30px 40px 36px 27px;
        box-sizing: border-box;
        position: relative;
    }

    .drugBox>h1 {
        height: 59px;
        line-height: 59px;
        font-size: 59px;
        text-align: left;
        font-weight: bold;
        font-family: "Arial";
        padding-bottom: 25px;
    }

    .drugBox ul{
        padding-bottom: 15px;
    }

    .drugBox ul li{
        list-style: none;
        line-height: 27px;
        padding-top: 14px;
    }

    .signatureBox {
        height: 52px;
    }

    .signature {
        width: 100%;
        padding: 0 40px 0 27px;
        box-sizing: border-box;
        position: absolute;
        bottom: 36px;
        left: 0;
    }

    .signature p {
        position: relative;
    }

    .signature img {
        max-width: 100%;
        position: absolute;
        left: 5px;
        bottom: 2px;
    }

    .signature .nameList {
        width: 50%;
        padding: 0;
    }

    .bottom {
        width: 100%;
        font-size: 0;
    }

    .bottom li {
        list-style: none;
        width: 33.3%;
        padding-top: 20px;
        font-size: 25px;
        box-sizing: border-box;
        padding-right: 50px;
    }

    .bottom li:last-of-type{
        padding-right: 0;
    }


    .bottom li span{
        display: block;
    }

    .bottom li p {
        width: 165px;
        line-height: 28px;
        border-bottom: 2px solid #000;
        text-align: left;
        margin-left: 5px;
        position: relative;
        top: 2px;
    }
</style>
<div class="main">
    <h1><span id="prescriptionTitle"></span> 处方笺</h1>
    <!-- 处方笺—患者姓名、性别、年龄、电话 -->
    <div class="flexAlign">
        <div class="flexMain nameList flexAlign">
            <span>姓名:</span>
            <p class="flexMain" id="patient-name"></p>
        </div>
        <div class="flexMain nameList flexAlign">
            <span>性别:</span>
            <p class="flexMain" id="patient-sex"></p>
        </div>
        <div class="flexMain nameList flexAlign">
            <span>年龄:</span>
            <p class="flexMain" id="patient-age"></p>
        </div>
    </div>
    <div class="flexAlign">
        <div class="flexMain nameList flexAlign">
            <span>电话:</span>
            <p class="flexMain" id="patient-telephone"></p>
        </div>
        <div class="flexMain nameList flexAlign">
            <span>费别:</span>
            <p class="flexMain" id="costCategory"></p>
        </div>
    </div>
    <!-- 处方笺—费别、门诊/住院病例号、科别/病区床位号 -->
    <div class="flexAlign">

        <div class="flexMain nameList flexAlign">
            <span>门诊/住院病例号:</span>
            <p class="flexMain" id="cardNumber"></p>
        </div>
        <div class="flexMain nameList flexAlign">
            <span>科别/病区床位号:</span>
            <p class="flexMain" id="departmentName"></p>
        </div>
    </div>
    <!-- 处方笺—临床诊断、皮试结果、处方日期 -->
    <div class="flexAlign">
        <div class="flexMain nameList flexAlign">
            <span>临床诊断:</span>
            <p class="flexMain" id="diagnosed"></p>
        </div>
    </div>
    <div class="flexAlign">
        <div class="flexMain nameList flexAlign">
            <span>皮试结果:</span>
            <p class="flexMain" id="stResults"></p>
        </div>
        <div class="flexMain nameList flexAlign" style="text-align: center;">
            <span>处方日期:</span>
            <p class="flexMain" id="createTime-year"></p>
            <span>年</span>
            <p class="flexMain" id="createTime-month"></p>
            <span>月</span>
            <p class="flexMain" id="createTime-day"></p>
            <span>日</span>
        </div>
    </div>
    <!-- 处方笺—处方、医生签名 -->
    <div class="drugBox" >
        <h1>Rp：</h1>
        <div id="drugList"></div>
        <!-- <ul>
            <li>10g*9包 袋装10克（含对乙酰氨基酚0.2克）  x1</li>
            <li>用法：1天2次，1次2片，口服</li>
        </ul>
        <ul>
            <li>10g*9包 袋装10克（含对乙酰氨基酚0.2克），袋装10克（含对乙酰氨基酚0.2克）   x2</li>
            <li>用法：1天2次，1次2片，口服</li>
        </ul> -->
        <div class="signatureBox">
            <div class="signature">
                <div class="nameList fr">
                    <div class="flexAlign">
                        <span>医生签名（盖章）：</span>
                        <!--<p class="flexMain" id="signImgUrl"><img src="" alt=""></p>-->
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- 处方笺—审核、调配、医师 -->
    <ul class="bottom flexAlign">
        <li class="flexMain flexAlign">
            <span>审核:</span>
            <p class="flexMain" id="auditStatus"></p>
        </li>
        <li class="flexMain flexAlign">
            <span>调配:</span>
            <p class="flexMain" id="blenderName"></p>
        </li>
        <li class="flexMain flexAlign">
            <span>医师:</span>
            <p class="flexMain" id="source-name"></p>
        </li>
    </ul>
    <!-- 处方笺—核对/发药、药品金额 -->
    <ul class="bottom flexAlign">
        <li class="flexMain flexAlign">
            <span>核对/发药:</span>
            <p class="flexMain" id="fddsName"></p>
        </li>
        <li class="flexMain flexAlign">
            <span>药品金额（元）:</span>
            <p class="flexMain" id="amount"></p>
        </li>
        <li style="width: 45px;"></li>
    </ul>
</div>
</body>
<script src="../../res/plugins/bootstrap/js/jquery.min.js?v=2.1.4"></script>
<script src="../../res/js/comm.js"></script>
<script type="text/javascript">
    Date.prototype.format = function (fmt) {
        var o = {
            "M+": this.getMonth() + 1,                //月份
            "d+": this.getDate(),                     //日
            "h+": this.getHours(),                    //小时
            "m+": this.getMinutes(),                  //分
            "s+": this.getSeconds(),                  //秒
            "S": this.getMilliseconds(),             //毫秒
            "TT": this.getHours() < 12 ? "AM" : "PM"
        };
        if (/(y+)/.test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "")
                .substr(4 - RegExp.$1.length));
        }
        for (var k in o) {
            if (new RegExp("(" + k + ")").test(fmt)) {
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k])
                    : (("00" + o[k]).substr(("" + o[k]).length)));
            }
            ;
        }
        return fmt;
    }

    $(function () {
        $.ajax({
            timeout: 60000,
            url: prescriptHttpUrl + "/prescription-rest/openx/rest/PrescriptionQueryService/queryPrescription",
            type: 'POST',
            contentType: "application/json",
            data: JSON.stringify({prescriptionId: decodeURI(getQueryString('prescriptionId'))}),
            success: function (data) {
                console.log(data)
                if (data)initContent(data);
                else window.alert('此订单无处方单数据！');
            },
            error: function (xhr, status, error) {
                window.alert('此订单无处方单数据！');
            }
        });
    });

    function initContent(data) {
        $("#prescriptionTitle").html(data.hospitalName?data.hospitalName:'');
        $('#patient-name').html(data.patientName ? data.patientName : '');
        var patientAge = data.patientAge ? data.patientAge : '';
        if (patientAge !== '') {
            if (patientAge >= 3) {
                patientAge = Math.ceil(patientAge) + '岁';
            } else {
                var age = patientAge.toString().split('.');
                if (age.length > 1) {
                    var month = '0.' + age[1]
                    month = Math.ceil(month * 12);
                    if (month === 12) {
                        patientAge = (parseInt(age[0]) + 1) + '岁'
                    } else {
                        patientAge = age[0] + '岁' + month + '月'
                    }
                } else {
                    patientAge = age[0] + '岁'
                }
            }
        }
        $('#patient-age').html(patientAge);
        var sex = data.patientSex;
        if (sex == 'FEMALE')sex = '女';
        else if (sex == 'MALE')sex = '男';
        $('#patient-sex').html(sex ? sex : '');
        $('#patient-telephone').html(data.contactInfo ? data.contactInfo : '');
        // var costCategory = data.costCategory;
        // if (costCategory == '0') costCategory = '医保';
        // else if (costCategory == '1') costCategory = '非医保';
        // $('#costCategory').html(costCategory ? costCategory : '');
        $('#costCategory').html('');
        $('#cardNumber').html(data.clinicCode ? data.clinicCode : '');
        $('#departmentName').html(data.dept ? data.dept : '');
        $('#diagnosed').html(data.preliminaryDiagnosis ? data.preliminaryDiagnosis : '');
        $('#stResults').html('');
        var  signImg = data.auditorSignImgUrl;
        $('#signImgUrl').find('img').attr('src', signImg ? signImg : '');
        var auditStatus = data.status;
        if (auditStatus === 'AUDIT_WAITING')auditStatus = '待审核';
        else if (auditStatus === 'AUDIT_PASS')auditStatus = '通过';
        else if (auditStatus === 'AUDIT_SUCCESS')auditStatus = '通过';
        else if (auditStatus === 'AUDIT_FAILED')auditStatus = '拒绝';
        $('#auditStatus').html(auditStatus ? auditStatus : '');
        $('#blenderName').html(data.distributor ? data.distributor : '');
        if (data.doctorId) {
            $('#source-name').html(data.doctorId ? data.doctorId : '');
        }
        $('#fddsName').html(data.reviewer ? data.reviewer : '');
        $('#amount').html('');
        var prescriptionGoodsList = data.prescriptionDrug;
        if (prescriptionGoodsList && prescriptionGoodsList.length > 0) {
            var temp = '<ul><li><%=goodsName%>  x<%=quantity%></li><li>用法：<%=usageDesc%></li></ul>';
            $.each(prescriptionGoodsList, function (index, item) {
                var goods = temp;
                goods = goods.replace(new RegExp("<%=goodsName%>", "g"), item.goodsName ? item.goodsName : '');
                goods = goods.replace(new RegExp("<%=quantity%>", "g"), item.quantity ? item.quantity : '');
                goods = goods.replace(new RegExp("<%=usageDesc%>", "g"), item.usageDesc ? item.usageDesc : '');
                $('#drugList').append(goods);
            });
        }
        if (data.prescriptionDate) {
            $('#createTime-year').html(new Date(data.prescriptionDate).format("yyyy"));
            $('#createTime-month').html(new Date(data.prescriptionDate).format("MM"));
            $('#createTime-day').html(new Date(data.prescriptionDate).format("dd"));
        }
        setTimeout(function () {
            window.print();
        }, 500);
    }

    //解析URL
    function getQueryString(name) {
        var r = window.location.search.substr(1).match(new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"));
        if (r != null) return unescape(r[2]);
        return null;
    }

</script>
</html>
